package com.ruoyi.project.erp.project.controller;

import java.util.List;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.erp.project.domain.ErpProject;
import com.ruoyi.project.erp.project.service.IErpProjectService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 项目Controller
 *
 * @author ruoyi
 * @date 2021-08-06
 */
@Controller
@RequestMapping("/erp/project")
public class ErpProjectController extends BaseController {
    private String prefix = "erp/project";

    @Autowired
    private IErpProjectService erpProjectService;

    @RequiresPermissions("erp:project:view")
    @GetMapping()
    public String project() {
        return prefix + "/project";
    }

    /**
     * 查询项目列表
     */
    @RequiresPermissions("erp:project:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(ErpProject erpProject) {
        startPage();
        List<ErpProject> list = erpProjectService.selectErpProjectList(erpProject);
        return getDataTable(list);
    }

    /**
     * 导出项目列表
     */
    @RequiresPermissions("erp:project:export")
    @Log(title = "项目", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(ErpProject erpProject) {
        List<ErpProject> list = erpProjectService.selectErpProjectList(erpProject);
        ExcelUtil<ErpProject> util = new ExcelUtil<ErpProject>(ErpProject.class);
        return util.exportExcel(list, "项目数据");
    }

    /**
     * 新增项目
     */
    @GetMapping("/add")
    public String add() {
        return prefix + "/add";
    }

    /**
     * 新增保存项目
     */
    @RequiresPermissions("erp:project:add")
    @Log(title = "项目", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(ErpProject erpProject) {
        return toAjax(erpProjectService.insertErpProject(erpProject));
    }

    /**
     * 修改项目
     */
    @GetMapping("/edit/{projectId}")
    public String edit(@PathVariable("projectId") Long projectId, ModelMap mmap) {
        ErpProject erpProject = erpProjectService.selectErpProjectByProjectId(projectId);
        mmap.put("erpProject", erpProject);
        return prefix + "/edit";
    }

    /**
     * 修改保存项目
     */
    @RequiresPermissions("erp:project:edit")
    @Log(title = "项目", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(ErpProject erpProject) {
        return toAjax(erpProjectService.updateErpProject(erpProject));
    }

    /**
     * 删除项目
     */
    @RequiresPermissions("erp:project:remove")
    @Log(title = "项目", businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids) {
        return toAjax(erpProjectService.deleteErpProjectByProjectIds(ids));
    }
}
